#pragma once
#include <string>
#include <vector>
#include <iostream>

const std::string http_sep = "\r\n";

class HttpRequest
{
public:
    HttpRequest()
        : _req_blank("\r\n")
    {
    }
    std::string GetLine(std::string &request, int &sep_pos)
    {
        sep_pos = request.find(http_sep);
        if (sep_pos == std::string::npos)
            return std::string();

        std::string line = request.substr(0, sep_pos);
        request.erase(0, sep_pos + http_sep.size());
        return line;
    }
    void DeSerialize(std::string &request)
    {
        while(true)
        {
            int sep_pos = -1;
            std::string line = GetLine(request, sep_pos);
            if (!line.empty() && sep_pos != 0)
            {
                _req_header.push_back(line);
            }
            else if (sep_pos == 0)
            {
                _req_content = request;
                break;
            }
        }
        _req_line = _req_header[0];
    }

    void Debug()
    {
        std::cout << "_req_header-->" << std::endl;
        for (auto &str : _req_header)
            std::cout << "-->" << str << std::endl;
        std::cout << "_req_blank-->" << _req_blank << std::endl;
        std::cout << "_req_content-->" << _req_content << std::endl;
    }

    ~HttpRequest()
    {
    }

private:
    std::string _req_line;
    std::vector<std::string> _req_header;
    std::string _req_blank;
    std::string _req_content;
};